$(function(){
	$('input[type="button"][name="search_client"]').on('click', function(){
		$.post("/r56_remonditeenus/s?action=search&task=client", {value : $('input[name="client"]').val()}, function(resp) {
			if (resp.name != "") {
				$('#client_name .name').text(resp.name);
				$('input[name="user_id"]').val(resp.id);
				$('input[name="user_name"]').val(resp.name);
				$('.search_client').toggle();
			}
		}, "json");
		return false;
	});

	$('input[type="button"][name="search_device"]').on('click', function(){
		$.post("/r56_remonditeenus/s?action=search&task=device", {value : $('input[name="device_name"]').val()}, function(resp) {
			if (resp.name != "") {
				$('.search_device .device_name').text(resp.name);
				$('input[name="device_id"]').val(resp.id);
				$('.search_device').toggle();
			}
		}, "json");
		return false;
	});
	
	$('a.delete').on('click', function(e){
		e.preventDefault();
		var id = $(this).attr('rel');
		var link = $(this);
		link.parents('tr').find('td').css('backgroundColor', 'red');
		$.post(link.attr('href'), {id : id}, function(){
			link.parents('tr').slideUp("slow");
		});
	});

	$('a.toggle').on('click', function(){
		var target = $(this).attr('rel');
		$(target).toggle();
		return false;
	});
});